<template>
  <div id="app-container">
    <!--条件查询表单-->
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="gymQueryVo.name" placeholder="场馆名"/>
      </el-form-item>
      <el-button type="primary" icon="el-icon-search" @click="getList(-1)">查询</el-button>
      <router-link to="/gym/add">
        <el-button type="primary">添加场馆</el-button>
      </router-link>
    </el-form>

    <!--数据显示列表-->
    <el-table :data="dataList" fit highlight-current-row>
<!--      <el-table-column type="index" label="序号" width="70">
        <template slot-scope="scope">
          {{pageSize * (currentPage - 1) + scope.$index + 1}}
        </template>
      </el-table-column>-->
      <el-table-column prop="name" label="场馆名称" width="120" ></el-table-column>
      <el-table-column prop="tel" label="电话" width="160" ></el-table-column>
      <el-table-column prop="address" label="地址" ></el-table-column>
      <el-table-column prop="email" label="邮箱" width="160"></el-table-column>
      <el-table-column prop="sort" label="排序" width="60" ></el-table-column>
      <el-table-column label="状态" width="120">
        <template slot-scope="scope">
          <span v-if="scope.row.state == 0">正常</span>
          <span v-if="scope.row.state == 1">闭馆</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="200">
        <template slot-scope="scope">
          <router-link :to="`/gym/edit/` + scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit">编辑</el-button>
          </router-link>
          <el-button type="danger" size="mini" icon="el-icon-delete" @click="handleRemove(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[1, 2, 3, 5]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>

  </div>
</template>
<script>
import gym from '../../api/gym'

  export default {
    data() {
      return {
        gymQueryVo: {},
        currentPage: 1,
        pageSize: 2,
        dataList: [],             // 分页数据
        total: 0,
      }
    },
    created(){
      this.getList();
    },
    methods:{
      getList(value){
        if(value == -1){
          this.currentPage = 1;
        }
        gym.getList(this.currentPage, this.pageSize, this.gymQueryVo).then(res =>{
          this.dataList = res.data.data;
          this.total = res.data.total;
        });
      },
      // 每页记录数发生变化
      handleSizeChange(size){
        this.pageSize = size;
        this.getList();
      },
      // 当前页发生变化
      handleCurrentChange(current){
        this.currentPage = current;
        this.getList();
      },
      // 删除
      handleRemove(id){
        this.$confirm("是否确定删除数据", "提示", {type: 'warning'})
          .then(()=>{
            gym.remove(id).then(res =>{
              // 弹出提示信息
              this.$message.success(res.message)
              this.currentPage = 1;
              this.getList();
            })
          })
          .catch(() =>{
            this.$message.info("取消删除操作")
          })
      },
    }
  }
</script>
